package com.gdcn.zb.sys.dao.impl;

import java.util.List;
import com.gdcn.zb.base.BaseDao;
import com.gdcn.zb.base.exception.DaoException;
import com.gdcn.zb.sys.dao.IUnitDao;
import com.gdcn.zb.sys.valueobject.Unit;

public class UnitDaoHibernate extends BaseDao implements IUnitDao{

	public void createUnit(Unit unit) throws DaoException {
		super.doCreateObject(unit);
		
	}

	public void deleteUnit(Unit unit) throws DaoException {
		super.doDeleteObject(unit);
		
	}

	public void deleteUnit(String id) throws DaoException {
		super.doDeleteObject(id);
	}

	public Unit findUnitById(String id) throws DaoException {
		return (Unit)super.doFindObjectById(id);
	}

	public void updateUnit(Unit unit) throws DaoException {
		super.doUpdateObject(unit);
		
	}

	protected Class getModelClass() {
		return Unit.class;
	}

	public List listUnitByParentId(String parentId) throws DaoException {
		List list = this.getHibernateTemplate().find("from Unit unit where unit.parentId='"+parentId +"'" );
		return list;
	}

	public Unit findUnitByFullName(String fullName) throws DaoException {
		List list = this.getHibernateTemplate().find("from Unit unit where unit.fullName='"+fullName +"'" );
		Unit unit = null;
		if(list!=null&&!list.isEmpty()){
			unit = (Unit)list.get(0);
		}
		return unit;
	}

}
